package 面向对象初级.方法.对象数组;

public class StudentTest {
    public static void main(String[] args) {
        //用数组声明20个学生
        Student[] students=new Student[20];
        //利用for循环给数组赋值
        for (int i = 0; i < 20; i++) {
            //20个学生初始化
            students[i] = new Student();
            //给数组中的对象进行赋值
            students[i].number=i+1;
            students[i].state=(int) (Math.random()*6)+1;
            students[i].score=(int) (Math.random()*100)+1;
        }
        //遍历数组并得到年级为3的学生信息
        for (int i = 0; i < students.length; i++) {
            if (students[i].state==3){
                students[i].toPrint();
            }
        }

        System.out.println("排序之前的效果");
        for (int i = 0; i < students.length; i++) {
            students[i].toPrint();
        }
        //
    }
}
